$(function () {
    $(".wrap-left,.wrap-right").css("height", window.innerHeight - 65);
    $(".wrap-left").css("padding", 0);
    $(".wrap-left").parent().css("padding", 0);
    $(".wrap-right").css("width", $(".wrap").width() - 250);
    $(".wrap-left,.wrap-right").css("float", "left");

    $.validator.setDefaults({
        errorElement: "span",
        errorClass: "text-danger",
        success: function (ele) {
            ele.removeClass("text-danger").addClass("text-success").html("<i class='glyphicon glyphicon-ok'></i>");
        },
        errorPlacement: function (error, element, eless) {
            $(element).next(".form-control-feedback").show();
            if ($(element).parent().hasClass("input-group")) {
                $(element).parent().parent().next(".help-block").html(error);
            } else {
                $(element).parent().next(".help-block").html(error);
            }

        }
    });
    $.ajaxSetup({
        headers: headers,
        error: function (jqXHR, textStatus, errorThrown) {
            showMessage(errorThrown, "error");
        }
    });
    if ($("#navbar").length > 0) {
        var navData = new Vue({
            el: '#navbar',
            data: {
                groups: [],
                projects: []
            },
            created: function () {
                var _this = this;
                $.getJSON("/indexNavData", {}, function (resp) {
                    if (resp.code != "0000") {
                        showMessage(resp.code || resp.desc, "error");
                    } else {
                        _this.groups = resp.data.groups;
                        _this.projects = resp.data.projects;
                    }
                })
            }
        });
    }

})
var messager = null;

function showMessage(content, type) {
    if (messager == null) {
        Messenger.options = {
            extraClasses: 'messenger-fixed messenger-on-bottom messenger-on-right',
            theme: 'block'
        }
        messager = Messenger().post({
            showCloseButton: true,
            type: type || "info",
            hideAfter: 3,
            message: content
        });
    } else {
        messager.update({
            type: type || "info",
            message: content
        });
    }
}

var csrfParameter = $("meta[name='_csrf_parameter']").attr("content");
var csrfHeader = $("meta[name='_csrf_header']").attr("content");
var csrfToken = $("meta[name='_csrf']").attr("content");
var headers = {};
headers[csrfHeader] = csrfToken;